﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace LogAnalyzer.ViewModel
{
    public class RoutingInfoViewModel : INotifyPropertyChanged
    {
        public string Message { get; set; }
        public Leaf Leaf { get; set; }
        public Table Table { get; set; }

        public RoutingInfoViewModel(Leaf leaf, Table table, Node from, string to = null, string key = null)
        {
            Leaf = leaf;
            Table = table;

            if (to == null && key == null)
            {
                Message = "Node State";
            }
            else if (from.MissingFromLeaf || from.MissingFromTable)
            {
                string missingSet = from.MissingFromLeaf ? "Leaf Set" : "Routing Table";
                Message = string.Format("Node {0}{4}Sent to node {1}{4}Node {2} is missing from {3}", from.nodeId, to, from.missingNode, missingSet, Environment.NewLine);
            }
            else
            {
                Message = string.Format("Node {0}{2}Sent to node {1}", from.nodeId, to, Environment.NewLine);
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string property)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
    }
}
